#define DEBUG
#include <cstdio>
#define MAXN 20000
#define MAXM 100000
#define MAXQ 5000

using namespace std;

class Side {
public:
  int x, y, d;

  static bool cmp(Side a, Side b) {
    return a.d<b.d;
  }
};

class Ques {
public:
  int x, id;

  static bool cmp(Ques a, Ques b) {
    return a.x<b.x;
  }
};

class Set {
public:
  int fa[MAXN+1], size[MAXN+1];

  void init(int n) {
    for (int i=1; i<=n; i++) {
      fa[i] = i, size[i] = 1;
    }
  }

  int getFa(int o) {
    if (fa[o]!=o) {
      fa[o] = getFa(fa[o]);
    }
    return fa[o];
  }

  void merge(int x, int y) {
    size[getFa(y)] += size[getFa(x)];
    fa[getFa(x)] = getFa(y);
  }
};

template<class T>
void sort(T *a, int l, int r, bool cmp(T a, T b)) {
  int i=l, j=r;
  T mid=a[(l+r)/2], temp;
  for (; i<=j; ) {
    for (; cmp(mid, a[j]); j--);
    for (; cmp(a[i], mid); i++);
    if (i<=j) {
      temp=a[i], a[i]=a[j], a[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    sort(a, i, r, cmp);
  }
  if (j>l) {
    sort(a, l, j, cmp);
  }
}

int main() {
#ifdef DEBUG
  freopen("0.in", "r", stdin);
  freopen("0.out", "w", stdout);
#endif

  int test;
  scanf("%d", &test);
  for (int testi=1; testi<=test; testi++) {
    static Side side[MAXM+1];
    static Set set;
    int n, m, q;
    scanf("%d %d %d", &n, &m, &q);
    set.init(n);
    for (int i=1; i<=m; i++) {
      scanf("%d %d %d", &side[i].x, &side[i].y, &side[i].d);
    }
    sort(side, 1, m, Side::cmp);

    static Ques ques[MAXQ+1];
    for (int i=1; i<=q; i++) {
      scanf("%d", &ques[i].x);
      ques[i].id = i;
    }
    sort(ques, 1, q, Ques::cmp);

    static int ans[MAXQ+1];
    ans[0] = 0;
    for (int i=1, j=1; i<=q; i++) {
      for (; j<=m && side[j].d<=ques[i].x; j++) {
	if (set.getFa(side[j].x)!=set.getFa(side[j].y)) {
	  ans[0] += set.size[set.getFa(side[j].x)]*set.size[set.getFa(side[j].y)]*2;
	  set.merge(side[j].x, side[j].y);
	}
      }
      ans[ques[i].id] = ans[0];
    }
    for (int i=1; i<=q; i++) {
      printf("%d\n", ans[i]);
    }
  }

  fcloseall();
  return 0;
}
